#include "base.h"
#include "unordered_map"
#include "unordered_set"

class Solution
{
public:
    int lengthOfLongestSubstring(string s)
    {
        int longest = 0;
        // int longest_begin = 0;
        // int longest_end = 0;

        // unordered_map<>
        for (int i = 0; i < s.length(); i++)
        {
            int begin = i;
            int end = i;

            //存入第一个字符
            unordered_set<char> buf;
            buf.insert(s.at(i));

            for (int j = i + 1; j < s.length(); j++)
            {
                //没有存
                if (buf.find(s.at(j)) == std::end(buf))
                {
                    buf.insert(s.at(j));
                    end = j;
                }
                else
                { //重复了. 当前的j是无效的，要-1
                    break;
                }
            }
            if (end - begin + 1 > longest)
            {
                longest = end - begin + 1;
            }
        }
        return longest;
    }
};

void main()
{
    Solution sol;
    auto a = sol.lengthOfLongestSubstring("au");
}